#ifndef FLIGHTSCHECKWINDOW_H
#define FLIGHTSCHECKWINDOW_H

#include <QLineEdit>
#include <QMainWindow>
#include <QNetworkAccessManager>
#include "calendardialog.h"
#include "choosecitydialog.h"
#include "customcontrol.h"
#include "models.h"
#include "ticketframe.h"
namespace Ui {
class FlightsCheckWindow;
}

class FlightsCheckWindow : public QMainWindow
{
    Q_OBJECT

public:
    static int book_orderid;
    explicit FlightsCheckWindow(QWidget *parent = nullptr);
    ~FlightsCheckWindow();
    void onTriggerFunction();                  // 接收来自首页信号的槽
    void updateDateDisplay(const QDate &date); // 更新 QLabel 和 QLineEdit
    void updateDateDisplay_return(const QDate &date);
    void updateLocationDisplay(const QList<Flight>& flightsList);
    QGroupBox *flightsBox;
    QGroupBox *flightsBox2;
    TicketFrame *ticketFrame = new TicketFrame();
    /*public slots:
    void receiveDate(const QDate& date);*///接收firstwindow传入的日期信息

private:
    Ui::FlightsCheckWindow *ui;
    ChooseCityDialog *cityDialog; // 对话框
    CalendarDialog *dateDialog;
    CalendarDialog *dateDialog2;
    bool eventFilter(QObject *watched, QEvent *event) override; // 声明 eventFilter
    QDate date;
    void populateFlightGrid(QGroupBox *flightsBox, const QList<Flight> &flightsList);
    void printflightlist(TicketFrame *ticketFrame,
                         QGroupBox *flightsBox,
                         const QList<Flight> &flightsList);
    void switchway(TicketFrame *ticketFrame, QGroupBox *flightsBox, QGroupBox *flightsBox2, bool one_way);
    void startlayout(TicketFrame *ticketFrame,QGroupBox *flightsBox,bool one_way,bool adult,bool eco_class);
    QNetworkAccessManager *manager; // 网络访问管理器

private slots:
    void handleLineEditClick1(); // 槽函数：处理 LineEdit 点击
    void handleLineEditClick2(); // 槽函数：处理 LineEdit 点击
    void on_DepartEdit_2_textEdited(const QString &arg1);
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void on_MoreDate_clicked();
    //date part
    void onBookButtonClicked(const Flight &flight);
    // 槽函数：接收选择的城市名并更新 QLineEdit
    void updateLineEditWithCity1(const QString &cityName);
    void updateLineEditWithCity2(const QString &cityName);

    void onOrdersCreateRequestFinished();

    void on_OneWayradioButton_2_clicked();
    void on_RoundWayradioButton_2_clicked();
    void on_MoreDate_2_clicked();
};

#endif // FLIGHTSCHECKWINDOW_H
